home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
CTRACE2_
/
CTESTAPP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-10
|
2KB
|
84 lines
/*****
Driver program for CTRACE: A MESSAGE LOGGING CLASS
by William D. Cramer in Dr. Dobbs Journal #170, p. 44-55, 116-120.
*****/
/** CTestApp.c -- Demonstrates how to include the CTrace utility as part of your
** application. Functions it performs are showing/hiding the trace log window
** and setting the trace mask. To demonstrate the calls to Trace(),
** it uses the New and Open menu commands. **/
#include <CApplication.h> /* Application class definitions */
#include <CBartender.h> /* Bartender class definitions */
#include <Commands.h> /* standard command definitions */
#include "CTrace.h" /* Trace log class definitions */
/* external references */
extern CBartender *gBartender;
extern CTrace *gTrace;
/* Declare the application class */
struct CTestApp : CApplication
{
CTrace *itsTraceLog;
void ITestApp (void);
void DoCommand(long c);
void UpdateMenus(void);
};
/** ITestApp -- Initializes the application and the CTrace object. **/
void CTestApp::ITestApp(void)
{
CApplication::IApplication (4, 20480L, 2048L);
itsTraceLog = new (CTrace);
itsTraceLog->ITrace (100);
}
/** UpdateMenus -- Updates the Trace portion of the menus. **/
void CTestApp::UpdateMenus (void)
{
inherited::UpdateMenus ();
gBartender->EnableMenu (TRACE_MENU_ID);
gBartender->EnableCmd (TRACE_MENU_SHOW);
gBartender->EnableCmd (TRACE_MENU_MASK);
if (itsTraceLog->IsItVisible ())
gBartender->CheckMarkCmd (TRACE_MENU_SHOW, TRUE);
else
gBartender->CheckMarkCmd (TRACE_MENU_SHOW, FALSE);
}
/** DoCommand -- Processes application commands. **/
void CTestApp::DoCommand (long command)
{
int i; /* a loop counter */
static int addno=1; /* a counter for the demo adds */
switch (command)
{
case cmdNew : /* trace one value at mask TRACE_INFO */
gTrace->Trace (T_INFO, "one'sies add, data=%d", addno++);
break;
case cmdOpen : /* trace 32 messages, one at each mask value */
for (i=0; i<32; i++)
gTrace->Trace ((1L<<i), "Entry #%d, trace mask #%d (mask=0x%08lX)",addno++, i+1, (long)(1L<<i));
break;
case TRACE_MENU_SHOW :
itsTraceLog->ToggleTraceWindow ();
break;
case TRACE_MENU_MASK :
itsTraceLog->SetTraceMask ();
break;
default :
inherited::DoCommand (command);
}
}
/** main() -- Main routine of the demo program. **/
void main ()
{
gApplication = new (CTestApp);
((CTestApp*)gApplication)->ITestApp ();
gApplication->Run ();
gApplication->Exit ();
}